package hamsterpolice.todo.data;

import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class UserTable {
	
	/**
	 * Hidden constructor. Only static methods on this class.
	 */
	private UserTable(){}
	
	private static final String TAG = "UserTable";
	public static final String TABLE_NAME = "user";
	
	public static final String COLUMN_ID = "_id";
	public static final String COLUMN_USERNAME = "username";
	public static final String COLUMN_PASSWORD = "password";
	public static final String COLUMN_FIRSTNAME = "firstName";
	public static final String COLUMN_LASTNAME = "lastName";
	public static final String COLUMN_EMAIL= "email";
	
	private static final String TABLE_CREATE = 
			" CREATE TABLE " + TABLE_NAME + 
			" ( " + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
			+ COLUMN_USERNAME + " TEXT COLLATE NOCASE UNIQUE NOT NULL, " 
			+ COLUMN_PASSWORD + " TEXT COLLATE NOCASE NOT NULL, "
			+ COLUMN_FIRSTNAME + " TEXT COLLATE NOCASE NULL, "
			+ COLUMN_LASTNAME + " TEXT COLLATE NOCASE NULL, "
			+ COLUMN_EMAIL + " TEXT COLLATE NOCASE NULL ) ";
	
	/**
	 * Creates the user table
	 * @param db
	 */
	static void create(SQLiteDatabase db) {
		Log.i(TAG, "Creating table " + TABLE_NAME);
		db.execSQL(TABLE_CREATE);
	}

	/**
	 * Upgrades the user table
	 * @param db
	 * @param oldVersion
	 * @param newVersion
	 */
	static void upgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		if(oldVersion<4){
			db.execSQL("DROP TABLE " + TABLE_NAME);
			create(db);
		}
	}
	
}
